package com.nineclock.system.controller;

import com.nineclock.common.utils.CheckCodeUtil;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@RestController
@RequestMapping("verifyCode")
@Api(value = "验证码接口", tags = "系统服务")
@Slf4j
public class verifyCodeController {
    @Autowired
    private RedisTemplate redisTemplate;

    @GetMapping("code")
    public void verifyCode(String username, HttpServletResponse response) throws ServletException, IOException {
        ServletOutputStream os = response.getOutputStream();
        String checkCode = CheckCodeUtil.outputVerifyImage(100, 50, os, 4);
        redisTemplate.opsForValue().set(username,checkCode);
    }
}
